import gnomeapplet
import gtk
import gobject
from gettext import gettext as _

class AgendaAppletButton(gtk.EventBox):
	__gsignals__ = {
		"toggled" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
	}
	
	def __init__(self):
		gtk.EventBox.__init__(self)
		self.active = False
		self.set_visible_window(False)
		self.connect('button-press-event', self.on_button_press)
 		image = gtk.Image ()
		image.set_from_icon_name ("x-office-calendar",gtk.ICON_SIZE_SMALL_TOOLBAR)
		self.add (image)
		self.set_tooltip_markup(_("Show agenda"))
	
	def on_button_press(self, widget, event):
#		print "on_button_press"
		if event.button == 1:
			self.set_active(not self.active)
			return True
		
				
	def get_active(self):
		return self.active
	
	def set_active(self, active):
		changed = (self.active != active)
		self.active = active
		if changed:
			self.emit("toggled")
			
class AgendaApplet(gnomeapplet.Applet):
	def __init__(self, applet):
		gnomeapplet.Applet.__init__(self)
 
		self.applet = applet
		#self.applet.connect("change-orient", lambda applet, orient: self.set_layout_by_orientation(orient))
		popup_dir = applet.get_orient()

		#self.set_layout_by_orientation(popup_dir)
		self.show_all()
		self.applet.show_all()
		
		self.tray = AgendaAppletButton()
#		self.tray.connect('toggled-main', self.on_toggled_main)
#		self.tray.connect('toggled-arrow', self.on_toggled_arrow)
		self.applet.add(self.tray)
		self.show_all()
		
		#self.box.pack_end (self.button_arrow, False, False)
  
	def get_active_main (self):
		return self.button_main.get_active ()
	
	def set_active_main (self, is_active):
		self.button_main.set_active (is_active)
